#pragma once
#include "Singleton.h"
#include <thread>
#include <boost/asio.hpp>

class AsioIOServicePool : public Singleton<AsioIOServicePool>
{
	friend class Singleton<AsioIOServicePool>;
	using IOContext = boost::asio::io_context;
	using Work = boost::asio::io_context::work;
	using Workptr = std::unique_ptr<Work>;
public:
	~AsioIOServicePool();
	boost::asio::io_context& getIOContext();
	void stop();
private:
	AsioIOServicePool(size_t size = std::thread::hardware_concurrency());
	size_t _size;
	std::vector<IOContext> _io_contexts;
	std::vector<Workptr> _works;
	std::vector<std::thread> _threads;
	size_t _next_ioc;
};

